<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Common\Logic;
use Admin\Common\Excel;
class RechargeRecordController extends BaseController {
    private $HAND_LOGINC   = null;
    public function _initialize(){
    	parent::_initialize();
    	$this->HAND_LOGINC = new Logic();

    }
	//充值记录列表
    public function index(){
      $inout = I('request.inout','','trim');
      $this->assign('inout',$inout);
      $this->display();
    }


   public function RechargeRecord_list(){
        $start_time = I('request.start_time','','trim');
        $end_time = I('request.end_time','','trim');

        //如果两个为空，没有条件
        //否则 一个为空，一个有值，两个有值 
        if(!(empty($start_time) && empty($end_time))){ 
            $start_time = empty($start_time)?date("Y-m-d"):$start_time;
            $end_time = empty($end_time)?date("Y-m-d"):$end_time;
            if($start_time>$end_time){
                 $temp=$end_time;
                 $end_time=$start_time;
                 $start_time=$temp;
            }  

         $start_time = strtotime($start_time);
         $end_time = strtotime($end_time);
          $where['create_time'] = array(between,array($start_time,$end_time));
           // $str =" and create_time between '".time($start_time)."' and '".time($end_time)."'"; 
        } 
        $inout = I('request.inout','','trim');
        $where['inout'] = $inout;
        $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = '*';
        $_where_order_field["order"] = 'create_time desc';
        $_datalist= $this->_getListsFromModel('cash_transaction',$_where_order_field);
        // print_r($_datalist['page_html']);exit;
        $this->assign('lists',$_datalist);
        $this->assign('inout',$inout);
        $this->display();
   } 

   //导出excel
   public function export_excel(){
        $inout = I('request.inout','','trim');
        $where['inout'] = $inout;
        $start_time = I('request.start_time','','trim');
        $end_time = I('request.end_time','','trim');

        //如果两个为空，没有条件
        //否则 一个为空，一个有值，两个有值 
        if(!(empty($start_time) && empty($end_time))){ 
            $start_time = empty($start_time)?date("Y-m-d"):$start_time;
            $end_time = empty($end_time)?date("Y-m-d"):$end_time;
            if($start_time>$end_time){
                 $temp=$end_time;
                 $end_time=$start_time;
                 $start_time=$temp;
            }  

         $start_time = strtotime($start_time);
         $end_time = strtotime($end_time);
          $where['create_time'] = array(between,array($start_time,$end_time));
           // $str =" and create_time between '".time($start_time)."' and '".time($end_time)."'"; 
        } 

      $list = D('cash_transaction')->where($where)->order('create_time desc')->select();
     $data = array(array('序号','金额','来源','日期'));
      foreach ($list as $key => $value) {
        $array=array();
        if($inout ==1){
          $content = $value['target'];
        }else{
          $content = $value['source'];
        }
        array_push($array,$value['id'],$value['money'],$content,date('Y-m-d H:i:s',$value['create_time']));
        array_push($data,$array);
      }
       $title = "充值记录".date('Y-m-d H:i');
      if($inout ==1){
        $title = "消费记录".date('Y-m-d H:i');
      }
      $excel = new Excel();
      header("Content-type:text/html;charset=UTF-8");
      $excel->download($data,$title,'');
   }

   public function del_admin(){
          if(IS_POST){
        $allid = I('post.allid');
        $where = "id in (".$allid.")";
          $row = D('Admin')->where($where)->delete();
             if($row != flase){
                  $ret=array('state'=>'1','msg'=>"批量删除成功!");
            }else{
               $ret=array('staute'=>'0','msg'=>"批量删除失败！");
           }
        }else{
            $ret=array('staute'=>'0','msg'=>"批量删除失败,信息传递错误！");
        }

        //echo D('group_purchase')->getLastSql();

     $this->ajaxReturn($ret);

   }
}
